package Controller;

import Pojo.Student;

import Service.ServiceImpl.StudentServiceImpl;
import Service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auther wsy
 * @auther MI
 * @create Servlet_Jdbc_Maven.${PACKAGE_NAME}
 * @create 7:49
 * @create 2021/7/6 星期二
 */
@WebServlet("/updateUserById")
public class UpdateUserById extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        Student s = new Student();
        s.setId(Integer.valueOf(request.getParameter("id")));
        s.setName(request.getParameter("name"));
        s.setAddress(request.getParameter("address"));
        s.setAge(Integer.valueOf(request.getParameter("age")));
        s.setGender(request.getParameter("gender"));
        s.setPassword(request.getParameter("password"));
        s.setClassname(request.getParameter("classname"));
        s.setGroup(Integer.valueOf(request.getParameter("group")));

        StudentService studentService = new StudentServiceImpl();
        boolean status = studentService.updateUserById(s);
        if (status){
            request.getRequestDispatcher("/findAll").forward(request,response);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
